<template>
	<div class="order_list">
		<div style="width: 100%;text-align: center;" v-if="!order.length">
			暂无订单
		</div>
		<div v-if="order.length">
			<van-card :price="item.total+'.00'" :desc="'下单时间:'+item.create_time" :title="JSON.parse(item.goods)[0].g_name" v-for="(item,index) in order">
				<template #thumb>
					<van-image width="88" height="88" :src="$url+JSON.parse(item.goods)[0].g_picture" />
				</template>
				<template #num>
					共{{item.count}}件
				</template>
				<template #footer>
					<van-button size="mini" @click='delorder(item.id)'>删除订单</van-button>
					<!-- <van-button size="mini" @click=''>再次购买</van-button> -->
				</template>
			</van-card>
		</div>
	</div>
</template>

<script>
	import Vue from 'vue';
	import {
		Image as VanImage
	} from 'vant';
	import {
		Card
	} from 'vant';

	Vue.use(Card);
	Vue.use(VanImage);
	export default {
		data() {
			return {
				shows: true,
				order:[],
			}
		},
		mounted(){
			this.$http.get('/order/orderup',{
				u_id:this.$store.state.u_id
			}).then(res=>{
				this.order = res.data.orders
				// console.log(this.order)
				for(var i = 0 ; i<res.data.orders.length;i++){
					//获取地址id
					
					// console.log(res.data.orders[i].add_id)
				}
			})
		},
		methods:{
			delorder(id){
				this.$http.get('/order/del?id='+id).then(res=>{
					if(res.data.code==200){
						this.$http.get('/order/orderup',{
							u_id:this.$store.state.u_id
						}).then(res=>{
							this.order = res.data.orders
							// console.log(this.order)
						})
					}
				})
			},
		}
	}
</script>

<style>
	.order_list {
		position: fixed;
		width: 100%;
		top: 3.5rem;
		bottom: 0;
		overflow-y: auto;
	}
</style>
